/*
*******************************************************************************
* 核心JAVASCRIPT工具集
* Author: Huang Hong (Kevin Hongs)
* Support: kevin.hongs@gmail.com, +8613718308220
* Version: 1.0
*
* 函数命名说明:
* hs开头的为简单工具函数
* Hs开头的为自定义JS伪类
*
* 常用变量名释义:
* HsBI 浏览器信息
* HsTW 顶级窗口
* HsPW 父级窗口
* HsOW 开启当前窗口的窗口
* HsFW 开启当前窗口的对象
* HsFE 浮动窗聚焦节点对象
* FW   浮动窗对象
* LA   列表动作对象
* FA   表单动作对象
* TA   树结构动作对象
*******************************************************************************
*/

/**
 * 获取指定ID的对象
 */
function hsId(id) {
  return document.getElementById(id);
}

/**
 * 获取指定NAME的对象数组(IE下对部分节点可能无效)
 */
function hsName(name) {
  return document.getElementsByName(name);
}

/**
 * 获取指定标签名的对象数组
 */
function hsTagName(tagName) {
  return document.getElementsByTagName(tagName);
}

/**
 * 获取指定样式类名的对象数组
 */
function hsClassName(className) {
  return document.getElementsByClassName(className);
}

/**
 * 获取iFrame的window对象(支持多层路径)
 *
 * @author HuangHong
 */
function hsFrameWindow(frameName) {
  var a = frameName.split("/");
  var w = a[0] == "" ? HsTW : self;
  for (var i = 0; i < a.length - 1; i ++) {
    w = a[i] == ".." ? w.HsPW : w.hsFrameWindow(a[i]);
  }
  delete a;

  var iw = w.hsId(frameName);
  if (! iw) {
    iw = w.hsName(frameName)[0];
  }
  delete w;

  if (iw.contentWindow) {
    return iw.contentWindow
  }
  else {
    return iw.window;
  }
}

/**
 * 综合对象获取
 *
 * @author HuangHong
 */
function hs(s) {
  var t = s.substr(0, 1);
  var n = s.substr(1, s.length - 1);
  switch (t) {
    case "#": return hsId(n);
    case "$": return hsName(n);
    case "%": return hsTagName(n);
    case ".": return hsClassName(n);
    case "/": return hsFrameWindow(n);
  }
}

/**
 * HS工具集错误处理
 *
 * @author HuangHong
 */
function hsError(message, name, info, quiet) {
  if (self.debugOn) {
    if (name) {
      message += "\nNAME: " + name;
    }
    if (info) {
      message += "\nINFO: " + info;
    }
  }
  if (!self.quiteOn && !quiet) {
    alert(message);
  }
  return message;
}

/**
 * 获取浏览器信息(内核名称及版本号等)
 *
 * @author HuangHong
 */
function hsGetBrowserInfo() {
  var r = /(MSIE|Firefox|Chrome|Safari|Opera)[ \/]([\d\.]+)/;
  var m = navigator.userAgent.match(r);
  if (m == null) {
    return null;
  }

  var o = new Object();
  o.name            = m[1];
  o.version         = parseFloat(m[2]);
  o.platform        = navigator.platform;
  o.cookieEnabled   = navigator.cookieEnabled;
  o.systemLanguage  = navigator.systemLanguage;
  o.userLanguage    = navigator.userLanguage;
  return o;
}

/**
 * 获取CSS中定义的样式
 *
 * @author HuangHong
 */
function hsGetComputedStyle(element, styleName) {
  var computedStyle = null;

  // IE
  if (element.currentStyle) {
    computedStyle = element.currentStyle;
  }
  // W3C
  else if (window.getComputedStyle) {
    computedStyle = window.getComputedStyle(element, null);
  }

  if (! computedStyle) {
    computedStyle = new Array();
  }

  if (styleName) {
    return computedStyle[styleName];
  }
  return computedStyle;
}

/**
 * 获取一个对象的真实宽度(包含border, margin, padding)
 *
 * @author HuangHong
 */
function hsGetComputedWidth(element) {
  var computedStyle = hsGetComputedStyle(element);
  var width = hsParseInt(computedStyle.borderLeftWidth)
  + hsParseInt(computedStyle.borderRightWidth)
  + hsParseInt(computedStyle.marginLeft)
  + hsParseInt(computedStyle.marginRight)
  + hsParseInt(computedStyle.paddingLeft)
  + hsParseInt(computedStyle.paddingRight);
  + hsParseInt(computedStyle.width);
  return width;
}

/**
 * 获取一个对象的真实高度(包含border, margin, padding)
 *
 * @author HuangHong
 */
function hsGetComputedHeight(element) {
  var computedStyle = hsGetComputedStyle(element);
  var height = hsParseInt(computedStyle.borderTopWidth)
  + hsParseInt(computedStyle.borderBottomWidth)
  + hsParseInt(computedStyle.marginTop)
  + hsParseInt(computedStyle.marginBottom)
  + hsParseInt(computedStyle.paddingTop)
  + hsParseInt(computedStyle.paddingBottom);
  + hsParseInt(computedStyle.height);
  return height;
}

/**
 * 获取指定属性的节点
 *
 * @author HuangHong
 */
function hsGetElementsByAttribute(name, value, tagName) {
  if (tagName == null) {
    tagName = ["*"];
  }
  else if (typeof(tagName) != "object") {
    tagName = [tagName];
  }
  var attElements = [];
  for (var j = 0; j < tagName.length; j ++) {
    var elements = document.getElementsByTagName(tagName[j]);
    for (var i = 0; i < elements.length; i ++) {
      if (elements[i].getAttribute(name) == value) {
        attElements.push(elements[i]);
      }
    }
  }
  return attElements;
}

/** 数字操作相关函数 **/

/**
 * 解析整型
 *
 * @authro HuangHong
 */
function hsParseInt(string) {
  var num = parseInt(string);
  if (isNaN(num)) {
    num = 0;
  }
  return num;
}

/**
 * 解析浮点型
 *
 * @authro HuangHong
 */
function hsParseFloat(string) {
  var num = parseFloat(string);
  if (isNaN(num)) {
    num = 0;
  }
  return num;
}

/**
 * 数字格式化
 *
 * @author HuangHong
 */
function hsNumberFormat(number, decimals, decimalPoint, separator) {
  if (decimals == null) {
    decimals = 2;
  }
  if (decimalPoint == null) {
    decimalPoint = ".";
  }

  var str = number.toString();

  var a = str.split(".");
  if (!a[1]) {
    a[1] = "";
  }

  var n = hsParseInt(a[0]);
  var d = hsParseInt(a[1].substr(0, decimals));
  if (4 < hsParseInt(a[1].substr(decimals, 1))) {
    if (Math.floor(d / 10) < Math.floor((d + 1) / 10)) {
      d = 0;
      n = n + 1;
    }
    else {
      d = d + 1;
    }
  }
  n = n.toString();
  d = d.toString();

  var num = "";
  var dec = "";

  if (separator) {
    var s = "";
    while (n != "") {
      s = n.substr(n.length - 3, 3);
      n = n.substr(0, n.length - 3);
      num = s + separator + num;
    }
    while (d != "") {
      s = d.substr(0, 3);
      d = d.substr(3);
      dec = dec + separator + s;
    }
    if (num) {
      num = num.substr(0, num.length - 1);
    }
    if (dec) {
      dec = dec.substr(1);
    }
  }
  else {
    num = n;
    dec = d;
  }

  return num + decimalPoint + dec;
}

/** 数组操作相关函数 **/

/**
 * 获取对象所有的键组成的数组
 *
 * @author HuangHong
 */
function hsObjectKeys(obj) {
  var arr = [];
  for (var k in obj) {
    arr.push(k);
  }
  return arr;
}

/**
 * 获取对象所有的值组成的数组
 *
 * @author HuangHong
 */
function hsObjectValues(obj) {
  var arr = [];
  for (var k in obj) {
    arr.push(obj[k]);
  }
  return arr;
}

/**
 * 获取对象所有的属性的长度
 *
 * @author HuangHong
 */
function hsObjectLength(obj) {
  var i = 0;
  for (var k in obj) {
    i ++;
  }
  return i;
}

/**
 * 判断对象是否有属性
 *
 * @author HuangHong
 */
function hsObjectIsNull(obj) {
  for (var k in obj) {
    return false;
  }
  return true;
}

/** 文本操作相关函数 **/

/**
 * JSON解码
 *
 * @author HuangHong
 */
function hsJsonDecode(str) {
  if (!str) {
    return null;
  }
  try {
    if (typeof JSON != "undefined") {
      return JSON.parse(str);
    }
    else {
      return eval('('+str+')');
    }
  }
  catch (ex) {
    hsError(self.jsonDecodeErr, 'JSONDecode', str);
    return new Object();
  }
  return null;
}

/**
 * JSON编码
 *
 * @author HuangHong
 */
function hsJsonEncode(arr) {
  if (typeof JSON != "undefined") {
    return JSON.stringify(arr);
  }
  else {
    var e = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
    var m = {'\b': '\\b', '\t': '\\t', '\n': '\\n', '\f': '\\f', '\r': '\\r', '"' : '\\"', '\\': '\\\\'};

    function sEncode(str) {
      e.lastIndex = 0;
      return e.test(str) ?
        '"' + str.replace(e, function (a) {
          var c = m[a];
          return typeof c === 'string' ? c :
            '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
        }) + '"' :
        '"' + str + '"';
    }

    function aEncode(arr) {
      switch (arr.constructor) {
        case String: return sEncode(arr);
        case Number: return arr.toString();
        case Boolean: return arr.toString();
        case Array :
          var buf = [];
          for (i in arr) {
            buf.push(aEncode(arr[i]));
          }
          return '[' + buf.join(',') + ']';
        case Object:
          var buf = [];
          for (k in arr) {
            buf.push(k + ':' + aEncode(arr[k]));
          }
          return '{' + buf.join(',') + '}';
        default:
          return 'null';
      }
    }

    return aEncode(arr);
  }
}

/**
 * 解码HTML字串
 *
 * 将&amp;&lt;&gt;转为&<>
 *
 * @author HuangHong
 */
function hsHtmlDecode(text) {
  var div = document.createElement("div");
  div.innerHTML = text;
  if (typeof div.innerText != "undefined") { // For IE
    return div.innerText;
  }
  else {
    return div.textContent;
  }
}

/**
 * 编码HTML字串
 *
 * 将&<>转为&amp;&lt;&gt;
 *
 * @author HuangHong
 */
function hsHtmlEncode(html) {
  var div = document.createElement("div");
  if (typeof div.innerText != "undefined") { // For IE
    div.innerText = html;
  }
  else {
    div.textContent = html;
  }
  return div.innerHTML;
}

/**
 * 计算文本的宽度
 *
 * @author HuangHong
 */
function hsTextWidth(text) {
  if (typeof text == "object") {
    text = text.innerHTML;
  }

  text = text.replace(/<.+?>/gm, " ");
  text = text.replace(/[\t\r\n]/gm, " ");
  text = text.replace(/ {2,}/gm, " ");
  text = text.trim();
  text = hsHtmlDecode(text);

  var div = document.createElement("div");
  var span = document.createElement("span");
  div.style.width = "0px";
  div.style.height = "0px";
  div.style.overflow = "hidden";
  div.style.visibility = "hidden";
  div.style.whiteSpace = "nowrap";
  div.appendChild(span);
  document.body.appendChild(div);

  span.innerHTML = text;
  var width = span.offsetWidth;

  document.body.removeChild(div);

  return {"text" : text, "width" : width};
}

/**
 * URL绑定参数
 *
 * @author HuangHong
 */
function hsUrlBindParam(url, name, value) {
  if (name) {
    name = encodeURI(name);
    value = encodeURIComponent(value);

    if (name.match(/%5B%5D$/i) == null) {
      var reg = new RegExp("([\?&])("+name+"=[^&#]*)([&#])?");
      var rst = reg.exec(url);

      if (rst) {
        var url1 = url.substr(0, rst.index);
        var url2 = url.substr(rst[0].length);

        if (rst[3]) {
          var flag = rst[3] == "#" ? "#" : (rst[1] == "?" ? "?" : "&");
          url = url1 + flag + url2;
        }
        else {
          url = url1;
        }
      }
    }

    if (value) {
      var arr = url.split("#", 2);
      url = arr[0];
      ecr = arr[1];
      delete arr;

      if (url.indexOf("?") == -1) {
        url += "?";
      }
      else {
        url += "&";
      }

      url += name + "=" + value;

      if (ecr) {
        url += "#" + ecr;
      }
    }
  }

  return url;
}

/**
 * URL绑定参数集
 *
 * @author HuangHong
 */
function hsUrlBindParams(url, params) {
  if (typeof params.length != "number") {
    for (var name in params) {
      var value = params[name];

      url = hsUrlBindParam(url, name, value);
    }
  }
  else {
    for (var i = 0; i < params.length; i ++) {
      // Is Select
      if (params[i].tagName && params[i].tagName == "SELECT") {
        var name = params[i].name;
        var value = null;
        if (name.substr(-2) != "[]") {
          value = hsGetSelectedOption(params[i]).value;
          url = hsUrlBindParam(url, name, value);
        }
        else {
          for (var j = 0; j < params[i].options.length; j ++) {
            if (false == params[i].options[j].selected) {
              continue;
            }
            value = params[i].options[j].value;
            url = hsUrlBindParam(url, name, value);
          }
        }
        continue;
      }

      // Is Radio or CheckBox
      if (params[i].tagName && params[i].tagName == "INPUT"
      && (params[i].type == "radio" || params[i].type == "checkbox")
       && params[i].checked == false) {
        continue;
      }

      var name = params[i].name;
      var value = params[i].value;
      url = hsUrlBindParam(url, name, value);
    }
  }

  return url;
}

/**
 * URL获取参数值
 *
 * @author HuangHong
 */
function hsGETValue(name) {
  var reg = new RegExp("[\?&]"+name+"=([^\?&#]*)");
  var arr = location.href.match(reg);
  if (arr){
    return arr[1];
  }
  else {
    return "";
  }
}

/** 文档节点操作相关函数 **/

/**
 * 获取子节点的 nodeType 为 Element(元素) 的节点
 *
 * @author HuangHong
 */
function hsChildElements(element) {
  var childs = element.childNodes;
  var nodes = new Array();
  for (var i = 0; i < childs.length; i ++) {
    if (childs[i].nodeType == 1) {
      nodes.push(childs[i]);
    }
  }
  nodes.firstChild = nodes[0];
  nodes.lastChild = nodes[nodes.length - 1];
  return nodes;
}

/**
 * 获取开始的 nodeType 为 Element 的节点
 *
 * @author HuangHong
 */
function hsFirstElement(element) {
  if (element.firstChild && element.firstChild.nodeType == 1) {
    return element.firstChild;
  }
  var childs = element.childNodes;
  for (var i = 0; i < childs.length; i ++) {
    if (childs[i].nodeType == 1) {
      return childs[i];
    }
  }
  return null;
}

/**
 * 获取结尾的 nodeType 为 Element 的节点
 *
 * @author HuangHong
 */
function hsLastElement(element) {
  if (element.lastChild && element.lastChild.nodeType == 1) {
    return element.lastChild;
  }
  var childs = element.childNodes;
  for (var i = childs.length - 1; i > 0; i --) {
    if (childs[i].nodeType == 1) {
      return childs[i];
    }
  }
  return null;
}

/**
 * 移动全部子节点
 *
 * @author HuangHong
 */
function hsMoveChilds(element, destElement) {
  var childs = element.childNodes;
  for (var i = 0; i < childs.length; i ++) {
    destElement.appendChild(childs[i]);
  }
}

/**
 * 清空全部子节点
 *
 * @author HuangHong
 */
function hsRemoveChilds(element) {
  var childs = element.childNodes;
  for (var i = 0; i < childs.length; i ++) {
    element.removeChild(childs[i], true);
  }
}

/** 下拉列表操作相关函数 **/

/**
 * 获取Select选项位置
 *
 * @author HuangHong
 */
function hsGetOptionPos(selectObj, itemValue) {
  for (var i = 0; i < selectObj.options.length; i++) {
    if (selectObj.options[i].value == itemValue) {
      return i;	
    }
  }
  return -1;
}

/**
 * 获取Select当前选中的位置
 *
 * @author HuangHong
 */
function hsGetSelectedOptionPos(selectObj) {
  for (var i = 0; i < selectObj.options.length; i++) {
    if (selectObj.options[i].selected == true) {
      return i;
    }
  }
  return -1;
}

/**
 * 获取Select选项
 *
 * @author HuangHong
 */
function hsGetOption(selectObj, itemValue) {
  var pos = hsGetOptionPos(selectObj, itemValue);
  if (pos > -1) {
    return selectObj.options[pos];
  }
  return null;
}

/**
 * 获取Select当前选中的选项
 *
 * @author HuangHong
 */
function hsGetSelectedOption(selectObj) {
  var pos = hsGetSelectedOptionPos(selectObj);
  if (pos > -1) {
    return selectObj.options[pos];
  }
  return null;
}

/**
 * 设置Select选项
 *
 * @author HuangHong
 */
function hsSetOption(selectObj, itemValue, itemText) {
  var pos = hsGetOptionPos(selectObj, itemValue);
  if (pos > -1) {
    selectObj.options[pos].text = itemText;
  }
  else {
    var objItem = new Option(itemText, itemValue);
    selectObj.options.add(objItem);
  }
}

/**
 * 设置Select当前选中项
 *
 * @author HuangHong
 */
function hsSetSelectedOption(selectObj, itemText) {
  var pos = hsGetSelectedOptionPos(selectObj);
  if (pos > -1) {
    selectObj.options[pos].text = itemText;
  }
}

/**
 * 检测Select是否存在某项
 *
 * @author HuangHong
 */
function hsHasOption(selectObj, itemValue) {
  if (hsGetOptionPos(selectObj, itemValue) > -1) {
    return true;
  }
  return false;
}

/**
 * 检测Select是否有被选中的项
 *
 * @author HuangHong
 */
function hsHasSelectedOption(selectObj) {
  if (hsGetSelectedOptionPos(selectObj) > -1) {
    return true;
  }
  return false;
}

/**
 * 删除Select选项
 *
 * @author HuangHong
 */
function hsRemoveOption(selectObj, itemValue) {
  var pos = hsGetOptionPos(selectObj, itemValue);
  if (pos > -1) {
    if (HsBI.name == "Firefox") {
      selectObj.remove(pos);
    }
    else {
      selectObj.options.remove(pos);
    }
  }
}

/**
 * 设置Select当前选中项
 *
 * @author HuangHong
 */
function hsRemoveSelectedOption(selectObj) {
  var pos = hsGetSelectedOptionPos(selectObj);
  if (pos > -1) {
    if (HsBI.name == "Firefox") {
      selectObj.remove(pos);
    }
    else {
      selectObj.options.remove(pos);
    }
  }
}

/**
 * 选中Select中的一个选项
 *
 * @author HuangHong
 */
function hsSelectOption(selectObj, itemValue) {
  var pos = hsGetSelectedOptionPos(selectObj);
  if (pos > -1) {
    selectObj.options[pos].selected = false;
  }
  pos = hsGetOptionPos(selectObj, itemValue);
  if (pos > -1) {
    selectObj.options[pos].selected = true;
  }
}

/** Javascript伪类 **/

/**
 * Cookie读写操作
 *
 * @author HuangHong
 * @param Number|Array expDays 过期天数
 * @param String path 路径
 * @param String domain
 * @param String secure
 */
function HsCookie(expDays, path, domain, secure) {
  var _this = this;
  _this.path = path;
  _this.domain = domain;
  _this.secure = secure;

  _this.getCookie = function(name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
      var j = i + alen;
      if (document.cookie.substring(i, j) == arg) {
        return _this.getCookieVal(j);
      }
      i = document.cookie.indexOf(" ", i) + 1;
      if (i == 0) break;
    }
    return "";
  };

  _this.setCookie = function(name, value, expires, path, domain, secure) {
    expires = expires ? expires : _this.expires;
    path = path ? path : _this.path;
    domain = domain ? domain : _this.domain;
    secure = secure ? secure : _this.secure;
    document.cookie = name + "=" + escape (value) +
      ((expires) ? "; expires=" + expires : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  };

  _this.delCookie = function(name, path, domain) {
    if (_this.getCookie(name)) {
      path = path ? path : _this.path;
      domain = domain ? domain : _this.domain;
      document.cookie = name + "=" +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
  };

  _this.getCookieVal = function(offset) {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1) {
      endstr = document.cookie.length;
    }
    return unescape(document.cookie.substring(offset, endstr));
  };

  _this.getExpDate = function(days, hours, minutes) {
    var expDate = new Date( );
    if (typeof days == "number" && typeof hours == "number" && typeof hours == "number") {
      expDate.setDate(expDate.getDate( ) + parseInt(days));
      expDate.setHours(expDate.getHours( ) + parseInt(hours));
      expDate.setMinutes(expDate.getMinutes( ) + parseInt(minutes));
      return expDate.toGMTString( );
    }
    return "";
  };

  // Object Init
  if (expDays) {
    if (typeof expDays == "number") {
      _this.expires = _this.getExpDate(expDays, 0, 0);
    }
    else {
      _this.expires = _this.getExpDate(expDays[0], expDays[1], expDays[2]);
    }
  }
}

/**
 * 绑定事件伪类
 *
 * @author HuangHong
 * @param Element node 绑定节点对象
 * @param String type 事件类型(click,mouseover等)
 * @param Function func 回调函数
 * @param Boolean uc
 * @param Boolean ar
 */
function HsEventListener(node, type, func, uc, ar) {
  if (! (node && type && func)) {
    return;
  }

  var _this = this;
  _this.node = node;
  _this.type = type;
  _this.func = func;
  _this.uc = uc ? true : false; // Use Capture
  _this.ar = ar ? true : false; // Auto Remove

  _this.add = function() {
    // IE
    if (_this.node.attachEvent){
      _this.node.attachEvent("on"+_this.type, _this.listener);
    }
    // Firefox
    else {
      _this.node.addEventListener(_this.type, _this.listener, _this.uc);
    }
  };

  _this.remove = function() {
    // IE
    if (_this.node.detachEvent) {
      _this.node.detachEvent("on"+_this.type, _this.listener);
    }
    // Firefox
    else {
      _this.node.removeEventListener(_this.type, _this.listener, _this.uc);
    }
  };

  _this.listener = function(ev) {
    ev = hsGetStandardEvent(ev);

    var re = _this.func(ev, _this);

    if (_this.ar) {
      _this.remove();
    }

    return re;
  };

  _this.add();
}

// 绑定事件
function hsAddEventListener(node, type, func, uc, ar) {
  return new HsEventListener(node, type, func, uc, ar);
}

// 注销事件
function hsRemoveEventListener(hsEvtObj) {
  hsEvtObj.remove();
}

// 事件标准化
function hsGetStandardEvent(e) {
  if (HsBI.name == "MSIE") {
    // For IE 6 TO 7 BUG
    if (window.event) {
      e = window.event;
    }

    e.target = e.srcElement;

    e.pageX = parseInt(e.clientX) - parseInt(document.body.clientLeft)
      + parseInt(document.documentElement.scrollLeft);
    e.pageY = parseInt(e.clientY) - parseInt(document.body.clientTop)
      + parseInt(document.documentElement.scrollTop);

    e.stopPropagation = function() {
      e.cancelBubble = true;
    };
    e.preventDefault = function() {
      e.returnValue = false;
    };
  }

  // If node is TEXT, find parent
  /*while (e.target && e.target.nodeType == 3) {
    e.target = e.target.parentNode;
  }*/

  return e;
}

// 禁止右键
function hsAllowRightMenu(allow) {
  if (allow) {
    document.oncontextmenu = null;
  }
  else {
    document.oncontextmenu = function(ev) {
      ev = hsGetStandardEvent(ev);
      ev.stopPropagation();
      ev.preventDefault();
      return false;
    };
  }
}

// 设置右键事件
function hsSetRightClick(node, func) {
  var EL = new HsEventListener(
    node, "mouseup",
    function(ev, el) {
      if (ev.button == 2) {
        el.func2();
      }
    }
  );
  EL.func2 = func;
}

/**
 * 简易AJAX构造器
 *
 * @author HuangHong
 * @param Function response 回调函数
 * @param String method 通讯方法(GET,POST)
 * @param String action 应用程序位置
 * @param String|Array|Object send 要发送的内容
 * @param Boolean async 是否采用异步
 */
function HsAjaxRequest(response, method, action, send, async) {
  var _this = this;
  _this.request   = null;
  _this.response  = response;             // 用来响应的函数
  _this.method    = method.toUpperCase(); // GET或POST
  _this.action    = action;               // 指定的HTTP地址
  _this.send      = send;                 // POST时被send出去的数据
  _this.async     = async;                // 同步(false)或异步(true)或手动(0)
  _this.share     = null;                 // 共享
  _this.header    = null;                 // 报头

  _this.init = function(send) {
    try {
      _this.request = new XMLHttpRequest();
    }
    catch (trymicrosoft) {
      try {
        _this.request = new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch (othermicrosoft) {
        try {
          _this.request = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (failed) {
          _this.request = null;
        }
      }
    }
    if (_this.request) {
      _this.errno = 0;
    }
    else {
      _this.errno = 1;
      hsError(self.ajaxRequestInitErr, "AJAXRequest");
      return;
    }

    if (_this.async === 0) {
      _this.setAsync();
    }
    else {
      _this.sendRequest();
    }
  };

  _this.setAsync = function(async) {
    _this.async = async ? true : false;
  };

  _this.setShare = function(key, value) {
    if (_this.share === null) {
      _this.share = new Array();
    }
    _this.share[key] = value;
  };

  _this.setHeader = function(key, value) {
    if (_this.header === null) {
      _this.header = new Array();
    }
    _this.header[key] = value;
  };

  _this.getResponse = function() {
    _this.setAsync(false);
    _this.mkSend();
    _this.doSend();
  };

  _this.sendRequest = function() {
    _this.setAsync(_this.async);
    _this.mkSend();
    _this.doSend();
  };

  _this.mkSend = function() {
    if (typeof(_this.send) == "object" && _this.send != null) {
      _this.send = _this.send.elements ? _this.send.elements : _this.send;

      var name = "";
      var value = "";
      var sendStr = "";

      // If is name:value
      if (typeof _this.send.length != "number") {
        for (name in _this.send) {
          value = _this.send[name];

          sendStr += "&"
            + encodeURI(name)
            + "="
            + encodeURIComponent(value);
        }
      }
      else {
        for (var i = 0; i < _this.send.length; i ++) {
          var node = _this.send[i];

          if (typeof(node) != "object") {
            sendStr += "&" + node;
            continue;
          }

          // Is Select
          if (node.tagName && node.tagName == "SELECT") {
            name = node.name;
            if (name.substr(-2) == "[]") {
              value = hsGetSelectedOption(node).value;
              sendStr += "&"
                + encodeURI(name)
                + "="
                + encodeURIComponent(value);
            }
            else {
              for (var j = 0; j < node.options.length; j ++) {
                if (false == node.options[j].selected) {
                  continue;
                }
                value = node.options[j].value;
                sendStr += "&"
                  + encodeURI(name)
                  + "="
                  + encodeURIComponent(value);
              }
            }
            continue;
          }

          // Is Radio or CheckBox
          if (node.tagName && node.tagName == "INPUT"
          && (node.type == "radio" || node.type == "checkbox")
           && node.checked == false) {
            continue;
          }

          // Is Others
          name = node.name;
          value = node.value;
          sendStr += "&"
            + encodeURI(name)
            + "="
            + encodeURIComponent(value);
        }
      }

      if (sendStr.length > 0) {
        _this.send = sendStr.substr(1);
      }
      else {
        _this.send = sendStr;
      }

      delete sendStr;
      delete name;
      delete value;
    }

    // 整理GET参数(当使用GET传递时)
    if (_this.method == "GET" && _this.send) {
      if (_this.action.indexOf("?") == -1) {
        _this.action += "?";
      }
      else {
        _this.action += "&";
      }
      _this.action += _this.send;
      _this.send = null;
    }
    // 当POST时设置Header
    else if (_this.method == "POST") {
      _this.setHeader("Content-Type", "application/x-www-form-urlencoded");
    }

    // 增加AJAX标识以供Hongs-CORE框架识别
    if (! /[\?&]?in_ajax=1/.test(_this.action)) {
      if (_this.action.indexOf("?") == -1) {
        _this.action += "?in_ajax=1";
      }
      else {
        _this.action += "&in_ajax=1";
      }
    }
  };

  _this.doSend = function() {
    if (_this.request == null) {
      _this.async = 0;
      _this.init();
    }

    // 异步设置
    if (_this.async == true) {
      _this.request.onreadystatechange = _this.back;
    }

    _this.request.open(_this.method, _this.action, _this.async);

    if (_this.header) {
      for (var key in _this.header) {
        _this.request.setRequestHeader(key, _this.header[key]);
      }
    }

    _this.request.send(_this.send);

    // 同步回调
    if (_this.async == false) {
      _this.back();
    }
  };

  _this.back = function() {
    // 通讯状态
    if (_this.request.readyState != 4) {
      return;
    }
    // 返回状态
    else if (_this.request.status != 200) {
      var s = _this.request.status+"";
      if (self.ajaxRequestStatusErr[s]) {
        hsError(self.ajaxRequestStatusErr[s], "AJAXRequest");
      }
      else {
        hsError(self.ajaxRequestStatusErr["0"], "AJAXRequest", "Status is "+s);
      }
      _this.errno = 2;
      _this.request = null;
    }
    else if (_this.request.responseText == null) {
      _this.request.responseText = "";
    }
    // 执行返回指令
    else if (_this.request.responseText.substr(0, 5) == 'EVAL:') {
      var s = _this.request.responseText.substr(5);
      try {
        eval(s);
        _this.errno = 3;
      }
      catch (ex) {
        hsError(self.ajaxRequestEvalErr, "AJAXRequest", ex.message);
        _this.errno = 4;
      }
      _this.request = null;
    }

    // 执行回调函数
    if (typeof _this.response == "function") {
      _this.response(_this.request);
    }
  };

  // Init
  _this.init();
}

/**
 * 分步AJAX构造器(从HsAjaxRequest继承)
 *
 * @author HuangHong
 */
function HsAjaxRequestStepper() {
  this.newMethod = HsAjaxRquest;
  this.newMethod(null, null, null, null, 0);
  //delete this.newMethod;

  var _this = this;

  _this.setResponse = function(response) {
    _this.response = response;
  };

  _this.setMethod = function(method) {
    _this.method = method;
  };

  _this.setAction = function(action) {
    _this.action = action;
  };

  _this.setSendData = function(send) {
    _this.send = send;
  };
}

/**
 * AJAX GET扩展函数
 *
 * @author HuangHong
 */
function hsAjaxRequestGet(action, send) {
  var AR = new HsAjaxRequest(null, "GET", action, send);
  return AR.request;
}

/**
 * AJAX POST扩展函数
 *
 * @author HuangHong
 */
function hsAjaxRequestPost(action, send) {
  var AR = new HsAjaxRequest(null, "POST", action, send);
  return AR.request;
}

/**
 * AJAX POST扩展函数
 *
 * @author HuangHong
 */
function hsAjaxRequestFloatPost(action, send) {
  var FL = new HsFloatLoading(self.submittingMsg);
  FL.start();

  var AR = new HsAjaxRequest(null, "POST", action, send);

  FL.stop();
  FL = null;

  if (AR.request == null) {
    return null;
  }

  var text = AR.request.responseText;
  var result = hsAjaxRequestResult(text, resultMsgType);

  if (result == null) {
    return null;
  }

  return result;
}
/**
 * AJAX Submit(Form)扩展函数
 *
 * @author HuangHong
 */
function hsAjaxRequestSubmit(formObj, submitMsg, resultMsgType) {
  if (typeof formObj == 'string') {
    formObj = document.forms[formObj];
  }
  if (typeof submitMsg == "undefined") {
    submitMsg = self.submittingMsg;
  }
  if (typeof resultMsgType == "undefined") {
    resultMsgType = self.resultMsgType;
  }

  var method = formObj.method;
  var action = formObj.action;
  var send = formObj.elements;

  var FL = new HsFloatLoading(submitMsg);
  FL.start();

  var AR = new HsAjaxRequest(null, method, action, send);

  FL.stop();
  FL = null;

  if (AR.request == null) {
    return null;
  }

  var text = AR.request.responseText;
  var result = hsAjaxRequestResult(text, resultMsgType);

  if (result == null) {
    return null;
  }

  return result;
}

/**
 * AJAX Get Result
 *
 * msgType取值:
 * 0: 发出失败消息
 * 1: 发出成功消息
 * 2: 发出所有消息
 * 3: 不发出任何消息
 *
 * @author HuangHong
 */
function hsAjaxRequestResult(text, msgType) {
  if (text === null) {
    return null;
  }
  if (typeof text == "object") {
    text = text.responseText;
  }
  if (typeof text == "string") {
    text = text.trim();
  }
  else {
    text = "";
  }

  if (typeof msgType == "undefined") {
    msgType = self.resultMsgType;
  }

  var cmd = text.substr(0, 5);
  var str = text.substr(5);
  var rst = {};
  if (cmd == 'EVAL:') {
    // EVAL模式
    try {
      eval(str);
    }
    catch (ex) {
      hsError(self.ajaxRequestEvalErr, "AJAXRequestResult", ex.message);
    }
    return null;
  }

  if (cmd == "JSON:") {
    // JSON模式
    if (str) {
      rst = hsJsonDecode(str);
      rst.__result  = rst.__result  ? rst.__result  : false;
      rst.__message = rst.__message ? rst.__message : "";
    }
    else {
      rst.__result  = false;
      rst.__message = "";
    }
  }
  else {
    // 消息模式(兼容旧的模式)
    if (text == "OK" || text.substr(0, 3) == "OK:") {
      rst.__message = text.length > 3 ? text.substr(3) : "";
      rst.__result = true;
    }
    else {
      rst.__message = text;
      rst.__result = false;
    }
  }

  if (msgType != 3) {
    if (rst.__message) {
      alert(rst.__message);
    }
    else {
      if (rst.__result) {
        if (msgType == 1 || msgType == 2) {
          alert(self.successMsg);
        }
      }
      else {
        if (msgType == 0 || msgType == 2) {
          alert(self.failedMsg);
        }
      }
    }
  }

  return rst;
}

/** 浮动窗相关 **/

/**
 * 浮动遮罩
 *
 * @author HuangHong
 * @param Element beforeNode 上层节点
 * @param Element innerNode 所在节点
 */
function HsFloatCover2(beforeNode, innerNode) {
  var _this = this;

  _this.beforeNode = beforeNode;
  _this.innerNode = innerNode;

  _this.bodyScroll = null;
  _this.lastCall = null;

  _this.init = function() {
    // 遮罩唯一
    if (! _this.innerNode) {
      _this.cover = hsId("hsFloatCover");
    }

    if (! _this.cover) {
      _this.cover = document.createElement("div");

      if (! _this.innerNode) {
        _this.cover.id = "hsFloatCover";
        _this.cover.style.zIndex = 999999;
      }

      _this.cover.style.display = "none";
      _this.cover.style.visibility = "hidden";
      _this.cover.style.position = "absolute";
      _this.cover.style.left = "0px";
      _this.cover.style.top = "0px";

      /**
       * 半透明样式:
       * filter: alpha(opacity=50);
       * opacity: 0.5;
       * -moz-opacity: 0.5;
       * -khtml-opacity: 0.5;
       */

      var s1 = 'position:absolute;left:0px;top:0px;';
      var s2 = 'width:100%;height:100%;';
      var s3 = 'width:auto;white-space:nowrap;';
      var so = 'filter:alpha(opacity=0);opacity:0;-moz-opacity:0;-khtml-opacity:0;';
      var sf = '<iframe frameborder="no" scrolling="no" width="100%" height="100%" src="about:blank"></iframe>';

      _this.cover.innerHTML = '<div style="'+s1+s2+so+'">'+sf+'</div><div style="'+s1+s2+'" class="hsFloatCoverFilter"></div><div style="'+s1+s3+'" class="hsFloatCoverMsgbox"></div>';

      if (! _this.innerNode) {
        document.body.appendChild(_this.cover);
      }
      else {
        if (_this.innerNode.style.position != "relative"
         || _this.innerNode.style.position != "absolute") {
            _this.innerNode.style.position  = "relative";
        }
        _this.innerNode.appendChild(_this.cover);
      }

      _this.setBeforeNode();
    }
  };

  _this.show = function(msg) {
    _this.setMsg(msg);

    // 设置所处位置
    if (!_this.innerNode && self.HsActiveWindows && self.HsActiveWindows.length > 0) {
      if (msg) {
        _this.setAfterNode(self.HsActiveWindows[self.HsActiveWindows.length - 1]);
      }
      else {
        for (var i = self.HsActiveWindows.length - 1; i >= 0; i --) {
          if (self.HsActiveWindows[i].withCover) {
            _this.setBeforeNode(self.HsActiveWindows[i]);
            break;
          }
        }
      }
    }

    _this.cover.style.display = "block";
    _this.cover.style.visibility = "visible";

    // 开启尺寸监听
    _this.setResize(true);
  };

  _this.hide = function(del) {
    _this.setMsg();

    // 检查所处位置
    if (!del && !_this.innerNode && self.HsActiveWindows && self.HsActiveWindows.length > 0) {
      for (var i = self.HsActiveWindows.length - 1; i >= 0; i --) {
        if (self.HsActiveWindows[i].withCover) {
          _this.setBeforeNode(self.HsActiveWindows[i]);
          return;
        }
      }
    }

    _this.cover.style.display = "none";
    _this.cover.style.visibility = "hidden";

    // 关闭尺寸监听
    _this.setResize(false);
  };

  _this.setMsg = function(msg) {
    var msgDiv = _this.cover.lastChild;

    if (msg) {
      if (msg !== true && msg !== 1) {
        msgDiv.innerHTML = msg;
        msgDiv.style.display = "block";
        msgDiv.style.visibility = "visible";

        var coverDisplay = _this.cover.style.display;
        var coverVisibility = _this.cover.style.visibility;
        _this.cover.style.display = "block";
        _this.cover.style.visibility = "hidden";

        var w = msgDiv.offsetWidth; //+ hsGetComputedWidth(msgDiv, true);
        var h = msgDiv.offsetHeight; //+ hsGetComputedHeight(msgDiv, true);
        if (!_this.innerNode) {
          msgDiv.style.left = ((document.documentElement.clientWidth - w) / 2)
            + document.documentElement.scrollLeft
            + "px";
          msgDiv.style.top = ((document.documentElement.clientHeight - h) / 2)
            + document.documentElement.scrollTop
            + "px";
        }
        else {
          msgDiv.style.left = ((_this.innerNode.offsetWidth - w) / 2) + "px";
          msgDiv.style.top = ((_this.innerNode.offsetHeight - h) / 2) + "px";
        }

        _this.cover.style.display = coverDisplay;
        _this.cover.style.visibility = coverVisibility;

        msgDiv.style.visibility = "visible";
      }

      if (!_this.innerNode && _this.lastCall != 1) {
        _this.lastCall = 1;
        _this.bodyScroll = {
          "scroll" : document.body.scroll,
          "overflow" : document.body.style.overflow
        };
        document.body.scroll = "no";
        document.body.style.overflow = "hidden";
      }
    }
    else {
      if (msg !== false && msg !== 0) {
        msgDiv.innerHTML = "";
        msgDiv.style.display = "none";
        msgDiv.style.visibility = "hidden";
      }

      if (!_this.innerNode && _this.lastCall != 0) {
        _this.lastCall = 0;
        if (_this.bodyScroll) {
          document.body.scroll = _this.bodyScroll.scroll;
          document.body.style.overflow = _this.bodyScroll.overflow;
        }
      }
    }
  };

  _this.setZIndex = function(index) {
    _this.cover.style.zIndex = index;
  };

  _this.setBeforeNode = function(beforeNode) {
    if (beforeNode) {
      _this.beforeNode = beforeNode;
    }
    else {
      beforeNode = _this.beforeNode;
    }
    if (beforeNode) {
      beforeNode.parentNode.insertBefore(_this.cover, beforeNode);
      _this.setZIndex(beforeNode.style.zIndex - 1);
    }
  };

  _this.setAfterNode = function(afterNode) {
    if (afterNode.nextSibling) {
      afterNode.parentNode.insertBefore(_this.cover, afterNode.nextSibling);
    }
    else {
      afterNode.parentNode.appendChild(_this.cover);
    }
    _this.setZIndex(afterNode.style.zIndex + 1);
  };

  _this.setResize = function(on) {
    if (_this.innerNode) {
      _this.cover.style.width = _this.innerNode.offsetWidth + "px";
      _this.cover.style.height = _this.innerNode.offsetHeight + "px";
      return;
    }

    if (on) {
      _this.resize();
      if (!_this.resizeHandle) {
        _this.resizeHandle = setInterval(_this.resize, 1000);
      }
    }
    else {
      if (_this.resizeHandle) {
        clearInterval(_this.resizeHandle);
        _this.resizeHandle = null;
      }
    }
  };

  _this.resize = function() {
    if (_this.cover.style.display == "none") {
      return;
    }

    _this.cover.style.display = "none";

    var cw = parseInt(document.documentElement.clientWidth);
    var ch = parseInt(document.documentElement.clientHeight);
    var sw = parseInt(document.documentElement.scrollWidth);
    var sh = parseInt(document.documentElement.scrollHeight);
    sw = sw > cw ? sw : cw;
    sh = sh > ch ? sh : ch;

    _this.cover.style.display = "block";

    if (_this.resizeWidth == sw && _this.resizeHeight == sh) {
      return;
    }

    _this.resizeWidth = sw;
    _this.resizeHeight = sh;
    _this.cover.style.width = sw + "px";
    _this.cover.style.height = sh + "px";
  };

  _this.init();
}

var HsFloatCover = HsFloatCover2;

/**
 * 浮动加载提示
 *
 * @author HuangHong
 * @param String msg 提示消息
 * @param Element div 所处块中
 */
function HsFloatLoading(msg, div) {
  var _this = this;
  var _parent = null;

  _this.msg = msg;
  _this.div = div;
  _this.percent = 0;
  _this.maxSecond = 0;
  _this.runSecond = 0;
  _this.remSecond = 0;

  _this.init = function() {
    _parent = new HsFloatCover2(null, _this.div);
    _this.Parent = _parent; // 注册到对象中供外部访问
  };

  _this.start = function(msg) {
    _this.onStart();
    _parent.show(msg ? msg : _this.msg);
  };

  _this.stop = function() {
    _this.onStop();
    _parent.hide();
  };

  _this.loadPercent = function(percent) {
    _this.percent = percent;

    _parent.setMsg(_this.msg + " <b>" + percent + "%</b>");

    if (percent >= 100) {
      _this.close();
      _this.percent = 0;
    }
  };

  _this.loadTime = function(max) {
    _this.maxSecond = max;
    if (_this.runSecond == 0) {
      _this.timeHandle = setInterval(_this.loadTimeRun, 1000);
    }
  };

  _this.loadTimeRun = function() {
    _this.percent = Math.floor(_this.runSecond / _this.maxSecond * 100);

    _parent.setMsg(_this.msg+" <br/> "+loadingPercent+"<b>" +_this.percent+ "%</b> "
      +loadingRunSecond+"<b>" +_this.runSecond+ "</b> "
      +loadingRemSecond+"<b>" +_this.remSecond+ "</b>");

    if (_this.remSecond <= 0) {
      clearInterval(_this.timeHandle);
      _this.close();
      _this.maxSecond = 0;
      _this.runSecond = 0;
      _this.remSecond = 0;
    }
    else {
      _this.runSecond ++;
      _this.remSecond --;
    }
  };

  _this.onStart = function() {};
  _this.onStop = function() {};

  _this.init();
}

/**
 * 浮动块类
 *
 * @author HuangHong
 * @param Object|String box 浮动块对象或ID
 * @param Object|String bar 拖动条对象或ID, 为空则同浮动块
 */
function HsFloatBlock(box, bar) {
  var _this = this;
  _this.box = box;
  _this.bar = bar ? bar : box;

  if (typeof _this.box == "string") {
    _this.box = hsId(_this.box);
  }
  if (typeof _this.bar == "string") {
    _this.bar = hsId(_this.bar);
  }

  _this.init = function () {
    _this.backup = {};

    // 注册按下事件
    new HsEventListener(_this.bar, "mousedown", _this.down);
  };

  _this.down = function(evt) {
    // 登记光标位置误差
    var cs = hsGetComputedStyle(_this.box);
    var ow = _this.box.offsetWidth;
    var oh = _this.box.offsetHeight;
    _this.w = ow - hsParseInt(cs.borderLeftWidth) - hsParseInt(cs.borderRightWidth);
    _this.h = oh - hsParseInt(cs.borderTopWidth) - hsParseInt(cs.borderBottomWidth);
    _this.x = _this.box.offsetLeft - hsParseInt(cs.marginLeft) + hsParseInt(cs.paddingLeft);
    _this.y = _this.box.offsetTop - hsParseInt(cs.marginTop) + hsParseInt(cs.paddingTop);
    _this.px = _this.x - evt.clientX;
    _this.py = _this.y - evt.clientY;

    // 备份样式
    _this.backup.cursor = _this.box.style.cursor;
    _this.backup.position = _this.box.style.position;
    _this.backup.left = _this.box.style.left;
    _this.backup.top = _this.box.style.top;
    _this.backup.width = _this.box.style.width;
    _this.backup.height = _this.box.style.height;

    // 更改样式
    _this.box.style.cursor = "move";
    _this.box.style.position = "absolute";
    _this.box.style.left = _this.x + "px";
    _this.box.style.top = _this.y + "px";
    _this.box.style.width = _this.w + "px";
    _this.box.style.height = _this.h + "px";

    // 注册移动及弹起事件
    if (_this.moveEvent) {
      _this.moveEvent.remove();
      _this.moveEvent = null;
    }
    if (_this.upEvent) {
      _this.upEvent.remove();
      _this.upEvent = null;
    }
    _this.moveEvent = new HsEventListener(window.document, "mousemove", _this.move);
    _this.upEvent = new HsEventListener(window.document, "mouseup", _this.up);

    // 响应用户事件
    _this.onDown(evt, _this);
  };

  _this.move = function(evt) {
    var cw = parseInt(document.documentElement.clientWidth);
    var ch = parseInt(document.documentElement.clientHeight);

    if (evt.clientX > 0 && evt.clientX < cw && evt.clientY > 0 && evt.clientY < ch) {
      _this.x = _this.px + evt.clientX;
      _this.y = _this.py + evt.clientY;

      _this.box.style.left = _this.x + "px";
      _this.box.style.top = _this.y + "px";

      // 响应用户事件
      _this.onMove(evt, _this);
    }
  };

  _this.up = function(evt) {
    // 清除变量
    _this.w = null;
    _this.h = null;
    _this.x = null;
    _this.h = null;
    _this.px = null;
    _this.py = null;

    // 恢复样式
    _this.box.style.cursor = _this.backup.cursor;
    _this.box.style.position = _this.backup.position;
    _this.box.style.left = _this.backup.left;
    _this.box.style.top = _this.backup.top;
    _this.box.style.width = _this.backup.wdith;
    _this.box.style.height = _this.backup.height;
    _this.backup = {};

    // 注销移动及弹起事件
    _this.moveEvent.remove();
    _this.moveEvent = null;
    _this.upEvent.remove();
    _this.upEvent = null;

    // 响应用户事件
    _this.onUp(evt, _this);
  };

  _this.onDown = function() {};
  _this.onMove = function() {};
  _this.onUp = function() {};

  _this.init();
}

/**
 * 浮动窗类
 *
 * @author HuangHong
 * @param Element floatBox
 * @param Boolean withCover
 * @param Boolean withScroll
 *

使用举例:
var floatDiv = HsFloatDiv(浮动层对象, 遮盖层对象, 有滚动条);
floatDiv.show(); // 显示浮动窗
floatDiv.hide(); // 关闭浮动窗

 *
 */
function HsFloatWindow2(floatBox, withCover, withScroll) {
  var _this = this;

  _this.box = floatBox;
  _this.withCover = withCover ? true : false;
  _this.withScroll = withScroll ? true : false;
  _this.helpMsg = self.floatWindowHelpMsg;

  _this.pw = _this.ph = 0;
  _this.px = _this.py = 0;
  _this.sw = _this.sh = 0;
  _this.sx = _this.sy = 0;
  _this.si = _this.mi = false;

  _this.init = function() {
    _this.box.style.display = "block";
    _this.box.style.visibility = "hidden";
    _this.box.style.position = "absolute";
    _this.box.style.clear = "both";

    if (_this.box.offsetWidth > 0) {
      _this.pw = _this.box.offsetWidth;
      _this.ph = _this.box.offsetHeight;
    }
    else {
      _this.pw = hsGetComputedWidth(_this.box);
      _this.ph = hsGetComputedHeight(_this.box);
    }

    _this.box.style.display = "none";

    if (_this.withCover) {
      // 给box对象加上withCover标识
      _this.box.withCover = true;
      // 注册到对象中供外部访问
      _this.Cover = new HsFloatCover2(_this.box);
    }

    if (typeof self.HsActiveWindows == "undefined") {
      // 活动窗列表
      self.HsActiveWindows = new Array();
    }
  };

  _this.setMoveBar = function(element) {
    element.style.cursor = "default";
    new HsEventListener(element, 'mousedown', _this.down);
  };

  _this.setHideBtn = function(element) {
    element.style.cursor = "pointer";
    new HsEventListener(element, 'click', _this.hide);
  };

  _this.setRollBtn = function(element) {
    element.style.cursor = "pointer";
    new HsEventListener(element, 'click', _this.roll);
  };

  _this.setHelpBtn = function(element, msg) {
    element.style.cursor = "help";
    new HsEventListener(element, 'click', _this.help);
    if (msg) {
      _this.helpMsg = msg;
    }
  };

  _this.show = function(hide) {
    if (_this.si == true) {
      return;
    }
    _this.si = true;

    // 保证在父节点末尾
    if (_this.box.parentNode.lastChild != _this.box) {
      _this.box.parentNode.appendChild(_this.box);
    }

    // 放入活动窗口列表
    self.HsActiveWindows.push(_this.box);

    // 整理活动窗口列表
    var l = self.HsActiveWindows.length;
    for (var i = 0, j = l; i < l; i ++, j --) {
      // IE,FireFox,Safari: -2147483647 ~ 2147483648
      // Opara: -2147483584 ~ 2147483584
      // Chrome: -1000000 ~ 1000000
      self.HsActiveWindows[i].style.zIndex = 1000000 - (j * 2);
    }

    // 启用遮罩
    if (_this.withCover) {
      _this.Cover.show(hide);
    }

    // 禁止Scroll
    if (!_this.withScroll) {
      document.body.scroll = "no";
      document.body.style.overflow = "hidden";
    }

    // 移除焦点
    _this.focusElement = document.activeElement;
    try {
      _this.focusElement.blur();
    }
    catch (ex) {
    }

    _this.center();
    _this.box.style.display = "block";
    if (hide == true) {
      _this.box.style.visibility = "hidden";
    }
    else {
      _this.box.style.visibility = "visible";
    }

    _this.onShow();
  };

  _this.hide = function() {
    if (_this.si == false) {
      return;
    }
    _this.si = false;

    // 从活动窗口中移除本窗口
    for (var i = 0; i < self.HsActiveWindows.length; i ++) {
      if (self.HsActiveWindows[i] == _this.box) {
        self.HsActiveWindows.splice(i, 1);
        break;
      }
    }

    // 隐藏遮罩
    if (_this.withCover) {
      _this.Cover.hide();
    }

    // 开启Scroll
    if (!_this.withScroll) {
      document.body.scroll = "";
      document.body.style.overflow = "";
    }

    // 返还焦点
    try {
      _this.focusElement.focus();
    }
    catch (ex) {
    }

    _this.box.style.display = "none";
    _this.box.style.visibility = "hidden";

    _this.onHide();
  };

  _this.down = function(evt) {
    _this.mi = true;
    /*if (src.setCapture)
      src.setCapture();
    else if (window.captureEvents)
      window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);*/

    evt.target.style.cursor = "move";

    _this.px = parseInt(_this.box.style.left) - evt.clientX;
    _this.py = parseInt(_this.box.style.top) - evt.clientY;
    _this.sw = parseInt(document.documentElement.scrollWidth);
    _this.sh = parseInt(document.documentElement.scrollHeight);
    _this.sx = _this.sw - _this.pw;
    _this.sy = _this.sh - _this.ph;

    _this.moveEvent = new HsEventListener(window.document, 'mousemove', _this.move);
    _this.upEvent = new HsEventListener(window.document, 'mouseup', _this.up);
    _this.onDown();
  };

  _this.move = function(evt) {
    if (_this.mi == false) {
      return;
    }

    var x = evt.clientX + _this.px;
    if (x < 0 || _this.sw < _this.pw) {
      _this.box.style.left = "0px";
    }
    else if (x > _this.sx) {
      _this.box.style.left = _this.sx + "px";
    }
    else {
      _this.box.style.left = x + "px";
    }

    var y = evt.clientY + _this.py;
    if (y < 0 || _this.sh < _this.ph) {
      _this.box.style.top = "0px";
    }
    else if (y > _this.sy) {
      _this.box.style.top = _this.sy + "px";
    }
    else {
      _this.box.style.top = y + "px";
    }
  };

  _this.up = function(evt) {
    _this.mi = false;
    /*if (src.releaseCapture)
      src.releaseCapture();
    else if (window.captureEvents)
      window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);*/

    evt.target.style.cursor = "default";

    _this.px = parseInt(_this.box.style.left);
    _this.py = parseInt(_this.box.style.top);

    _this.moveEvent.remove();
    _this.upEvent.remove();
    _this.onUp();
  };

  _this.roll = function() {
    _this.onRoll(!_this.rolled);
    _this.rolled = !_this.rolled;
    _this.pw = _this.box.offsetWidth;
    _this.ph = _this.box.offsetHeight;
  };

  _this.help = function() {
    alert(_this.helpMsg);
  };

  _this.center = function() {
    // 调整位置到窗口中间
    var l = -1;
    var t = -1;
    if (_this.centerPos) {
      l = _this.centerPos[0];
      t = _this.centerPos[1];
    }
    if (l == -1) {
      l = parseInt(document.documentElement.scrollLeft) +
        ((parseInt(document.documentElement.clientWidth) - _this.pw) / 2);
    }
    if (t == -1) {
      t = parseInt(document.documentElement.scrollTop) +
        ((parseInt(document.documentElement.clientHeight) - _this.ph) / 2);
    }

    _this.px = (l > 0 ? l : 0);
    _this.py = (t > 0 ? t : 0);

    _this.box.style.left = _this.px + "px";
    _this.box.style.top = _this.py + "px";
  };

  _this.onShow = function() {};
  _this.onHide = function() {};
  _this.onRoll = function() {};
  _this.onDown = function() {};
  _this.onUp = function() {};

  _this.init();
}

/**
 * 浮动窗构造器
 *
 * @author HuangHong
 * @param Number width 宽
 * @param Number hieght 高
 * @param String scroll 滚动条样式(normal,auto,yes,no,x,y)
 * @param Boolean noMove
 * @param Boolean noClose
 * @param Boolean noCover
 * @param Boolean noScroll
 * @param String Object 窗体模板
 *

使用说明:
var FW = new HsFloatWindowCreator( 宽, 高 [, 滚动条 [, 不能移动 [, 不能关闭 [, 无遮罩层 [, 无滚动条, [窗体模板] ] ] ] ] ] );
FW.setTitle(浮动窗标题);                     // 如果层有title属性或iframe中的body有title则可不用使用该函数
FW.setContent(ID或URL[, 是否启用iframe]);    // 要使用iframe则第二个参数为true
FW.setContentHtml(内容代码);                 // 自定义内容区
FW.setOpenerWindow(当前所在的window对象)     // 设置开启窗口的window对象
FW.setHelpMsg(帮助消息);                     // 设置帮助消息(点击帮助按钮打开)
FW.open([ID或URL[, 是否启用iframe]]);        // 常规打开(在父窗口中央)
FW.openOnUserPos(横坐标, 纵坐标);            // 在用户指定位置打开
FW.openOnMousePos(事件对象);                 // 在鼠标位置打开
FW.close();                                  // 关闭浮动窗

窗体模板代码示例:
<table border="0" cellpadding="0" cellspacing="0" id="hsFloatWindowTitleBar%ID%" class="hsFloatWindowTitleBar" style="width:100%;">
  <tr>
    <td id="hsFloatWindowHelpBtn%ID%" class="hsFloatWindowHelpBtn" style="text-align:center;"> Help </td>
    <td id="hsFloatWindowMoveBar%ID%" class="hsFloatWindowMoveBar" style="text-align:center;"> Hongs Float Window </td>
    <td id="hsFloatWindowCloseBtn%ID%'" class="hsFloatWindowCloseBtn" style="text-align:center;"> Close </td>
  </tr>
</table>
<div id="hsFloatWindowContentBox%ID%" class="hsFloatWindowContentBox"></div>

 *
 */
function HsFloatWindowCreator(width, height, scroll, noMove, noClose, noCover, noScroll, tpl) {
  var _this = this;
  var _parent = null;

  // 默认宽高
  _this.id = Math.round(Math.random() * 10000);
  _this.width = width ? width : 0;
  _this.height = height ? height : 0;
  _this.scroll = scroll != null ? scroll : "normal";
  _this.noMove = noMove != null ? noMove : false;
  _this.noClose = noClose != null ? noClose : false;
  _this.noCover = noCover != null ? noCover : false;
  _this.noScroll = noScroll != null ? noScroll : false;

  _this.contentType = null; // 0为普通模式, 1为iframe模式, 2为html代码模式
  _this.openType = null; // 0为普通模式, 1为指定位置模式, 2为鼠标位置模式
  _this.isOpened = false;

  _this.init = function() {
    _this.container = document.getElementById("hsFloatWindowContainer");
    if (! _this.container) {
      _this.container = document.createElement("div");
      _this.container.id = "hsFloatWindowContainer";
      _this.container.style.width = "0px";
      _this.container.style.height = "0px";
      _this.container.style.visibility = "hidden";
      //_this.container.style.overflow = "hidden";
      document.body.appendChild(_this.container);
    }
    if (!tpl) {
      tpl = new Object();
      tpl.top = self.floatWindowTop;
      tpl.left = self.floatWindowLeft;
      tpl.right = self.floatWindowRight;
      tpl.bottom = self.floatWindowBottom;
      tpl.helpMsg = self.floatWindowHelpMsg;
      tpl.template = self.floatWindowTemplate;
    }
    else {
      if (tpl.top == undefined) {
        tpl.top = 0;
      }
      if (tpl.left == undefined) {
        tpl.left = 0;
      }
      if (tpl.right == undefined) {
        tpl.right = 0;
      }
      if (tpl.bottom == undefined) {
        tpl.bottom = 0;
      }
      if (tpl.helpMsg == undefined) {
        tpl.helpMsg = self.floatWindowHelpMsg;
      }
    }

    /** 创建浮动窗盒子 **/

    _this.top = tpl.top;
    _this.left = tpl.left;
    _this.right = tpl.right;
    _this.bottom = tpl.bottom;

    _this.box = document.createElement("div");
    _this.box.id = "hsFloatWindow" + _this.id;
    _this.box.className = "hsFloatWindow";
    _this.box.style.zIndex = 2147483647;
    _this.box.style.width = (_this.width + _this.left + _this.right) + "px";
    _this.box.style.height = (_this.height + _this.top + _this.bottom) + "px";
    _this.box.innerHTML = tpl.template.replace(/%ID%/g, _this.id);
    _this.container.appendChild(_this.box);

    _this.titleBar = hsId("hsFloatWindowTitleBar"+_this.id);
    _this.moveBar = hsId("hsFloatWindowMoveBar"+_this.id);
    _this.closeBtn = hsId("hsFloatWindowCloseBtn"+_this.id);
    _this.rollBtn = hsId("hsFloatWindowRollBtn"+_this.id);
    _this.helpBtn = hsId("hsFloatWindowHelpBtn"+_this.id);
    _this.content = hsId("hsFloatWindowContentBox"+_this.id);

    _this.content.style.width = _this.width + "px";
    _this.content.style.height = _this.height + "px";

    if (_this.scroll == "normal") {
      if (_this.width == 0) {
        _this.box.style.width = "";
        _this.content.style.width = "";
      }
      if (_this.height == 0) {
        _this.box.style.height = "";
        _this.content.style.height = "";
      }
    }

    /** 创建浮动窗对象 **/

    _parent = new HsFloatWindow2(_this.box, !_this.noCover, !_this.noScroll);

    if (_this.moveBar) {
      if (!_this.noMove) {
        _parent.setMoveBar(_this.moveBar);
      }
      else {
        _this.moveBar.className += "Dis";
      }
    }

    if (_this.closeBtn) {
      if (!_this.noClose) {
        _parent.setHideBtn(_this.closeBtn);
      }
      else {
        _this.closeBtn.className += "Dis";
      }
    }

    if (_this.rollBtn) {
      _parent.setRollBtn(_this.rollBtn);
    }

    if (_this.helpBtn) {
      _parent.setHelpBtn(_this.helpBtn, tpl.helpMsg);
    }

    delete tpl;

    // 关联基类事件
    _parent.onShow = _this.onShow;
    _parent.onHide = _this.onHide;
    _parent.onRoll = _this.onRoll;
    _parent.onDown = _this.onDown;
    _parent.onUp = _this.onUp;

    // 注册到对象中, 以供外部访问
    _this.Parent = _parent;
    _this.Cover = _parent.Cover;
  };

  _this.setTitle = function(title) {
    if (_this.moveBar) {
      _this.moveBar.innerHTML = title ? title : "&nbsp;";
    }
  };

  _this.setContent = function(id, useFrame, forceLoad) {
    if (_parent.si) {
      return;
    }

    if (!id) {
      hsError(self.floatWindowNoIdErr, "FloatWindow");
      return;
    }

    // 隐藏浮动窗
    _this.visible(false);

    if (useFrame) {
      // 检查是否是加载相同的内容
      if (forceLoad == false
       && _this.innerSrc == id) {
        _this.forceLoad = false;
        return;
      }
      else {
        _this.forceLoad = true;
      }

      // 内嵌地址
      _this.innerSrc = id;
      // 内联ID
      _this.innerId = "hsFloatWindowFrame"+_this.id;

      if (_this.contentType !== 1) {
        // 设定滚动条
        var scrolling;
        if (_this.scroll == "normal") {
          scrolling = "no";
        }
        else {
          // For IE 6
          if (_this.scroll == "auto" && HsBI.name == "MSIE" && HsBI.version < 7) {
            scrolling = "yes";
          }
          else {
            scrolling = _this.scroll;
          }
        }

        // 创建 iframe
        _this.content.innerHTML = '<iframe id="'+_this.innerId+'" name="'+_this.innerId+'" scrolling="'+scrolling+'" frameborder="no" width="100%" height="100%"></iframe>';
        _this.innerContent = hsId(_this.innerId);

        // 设置 iframe
        if (HsBI.name == "MSIE") { // For IE
          _this.innerContent.onreadystatechange = _this.onChange;
        }
        else {
          _this.innerContent.onload = _this.onChange;
        }
      }

      // 内容区类型
      _this.contentType = 1;
    }
    else {
      // 检查指定的div是否存在
      if (_this.openerWindow) {
        if (!_this.openerWindow.hsId(id)) {
          hsError(self.floatWindowNoInnerDivErr, "FloatWindow", "ID is " + id);
          return;
        }
      }
      else {
        if (!hsId(id)) {
          hsError(self.floatWindowNoInnerDivErr, "FloatWindow", "ID is " + id);
          return;
        }
      }

      // 内联ID
      _this.innerId = id;

      if (_this.contentType !== 0 && _this.contentType !== 2) {
        // 设定滚动条
        switch (_this.scroll) {
          case "auto": _this.content.style.overflow = "auto"; break;
          case "yes": _this.content.style.overflow = "scroll"; break;
          case "no": _this.content.style.overflow = "hidden"; break;
          case "x":
            _this.content.style.overflow = "hidden";
            _this.content.style.overflowX = "auto";
          break;
          case "y":
            _this.content.style.overflow = "hidden";
            _this.content.style.overflowY = "auto";
          break;
          default:
            _this.content.style.overflow = "";
          break;
        }
      }

      // 内容区类型
      _this.contentType = 0;
    }
  };

  _this.setContentHtml = function(html) {
    if (_parent.si) {
      return;
    }

    if (_this.contentType !== 0 && _this.contentType !== 2) {
      // 设定滚动条
      switch (_this.scroll) {
        case "auto": _this.content.style.overflow = "auto"; break;
        case "yes": _this.content.style.overflow = "scroll"; break;
        case "no": _this.content.style.overflow = "hidden"; break;
        case "x":
          _this.content.style.overflow = "hidden";
          _this.content.style.overflowX = "auto";
        break;
        case "y":
          _this.content.style.overflow = "hidden";
          _this.content.style.overflowY = "auto";
        break;
        default:
          _this.content.style.overflow = "";
        break;
      }
    }

    // 内容区类型
    _this.contentType = 2;

    // 清除内容
    hsRemoveChilds(_this.content);

    // 写入内容
    _this.innerContent = document.createElement('div');
    _this.innerContent.innerHTML = html;
    _this.content.appendChild(_this.innerContent);
  };

  _this.setHelpMsg = function(msg) {
    _parent.helpMsg = msg;
  };

  _this.setOpenerWindow = function(o) {
    _this.openerWindow = o.innerWindow ? o.innerWindow : o;
  };

  _this.open = function(id, useFrame, forceLoad) {
    if (id != null) {
      _this.setContent(id, useFrame, forceLoad);
    }

    _this.openType = 0;
    _parent.centerPos = null;
    _parent.show(true);
  };

  _this.openOnUserPos = function(x, y, o) {
    if (o) {
      x += o.Parent.px + o.left;
      y += o.Parent.py + o.top;
      _this.openerWindow = o.innerWindow;
    }
    else if (!_this.openerWindow) {
      _this.openerWindow = window;
    }

    _this.openType = 1;
    _parent.centerPos = new Array(x, y);
    _parent.show(true);
  };

  _this.openOnMousePos = function(e, o) {
    e = hsGetStandardEvent(e);
    var x = e.pageX;
    var y = e.pageY;

    if (o) {
      x += o.Parent.px + o.left;
      y += o.Parent.py + o.top;
      _this.openerWindow = o.innerWindow;
    }
    else if (!_this.openerWindow) {
      _this.openerWindow = window;
    }

    _this.openType = 2;
    _parent.centerPos = new Array(x, y);
    _parent.show(true);
  };

  _this.close = function() {
    _parent.hide();
  };

  _this.visible = function(visible) {
    _this.box.style.visibility = visible ? "visible" : "hidden";
    _this.visibled = visible;
  };

  _this.onShow = function() {
    _this.onOpen();

    if (_this.contentType == 1) {
      if (_this.forceLoad == true) {
        var src = _this.innerSrc;
        if (src.indexOf("?") == -1) {
          src += "?in_fw=1";
        }
        else {
          src += "&in_fw=1";
        }

        // 开启加载提示
        _this.Cover.setMsg(self.loadingMsg);
        // 开始加载页面
        _this.innerContent.setAttribute("src", src);
      }
      else {
        _this.onChange();
      }
    }
    else {
      if (_this.contentType == 0) {
        if (_this.openerWindow) {
          _this.innerContent = _this.openerWindow.hsId(_this.innerId);
        }
        else {
          _this.innerContent = hsId(_this.innerId);
        }
        _this.innerParent = _this.innerContent.parentNode;
        _this.innerBrother = _this.innerContent.nextSibling;

        hsRemoveChilds(_this.content);
        _this.content.appendChild(_this.innerContent);

        // 标题
        if (_this.moveBar
          && (_this.moveBar.innerHTML.trim() == ""
          || _this.moveBar.innerHTML.trim() == "&nbsp;")) {
            _this.setTitle(_this.innerContent.title
              ? _this.innerContent.title
              : "Untitled");
        }
      }

      // 尺寸
      if (_this.scroll == "normal") {
        _this.box.style.visibility = "hidden";
        _this.box.style.display = "block";

        _this.onResize2(true);
        if(!_this.resizeHandle) {
          _this.resizeHandle = setInterval(_this.onResize2, 500);
        }
      }

      _this.visible(true);
      _this.Cover.hide();

      _parent.center();
    }
  };

  _this.onHide = function() {
    try {
      _this.onClose();
    }catch (ex) {
    }
    if (_this.contentType == 0) {
      _this.innerParent.insertBefore(_this.innerContent, _this.innerBrother);
    }

    if (_this.contentType == 2) {
      _this.content.removeChild(_this.innerContent);
    }

    if (_this.scroll == "normal" && _this.resizeHandle) {
      clearInterval(_this.resizeHandle);
      _this.resizeHandle = null;
    }

    _this.visibled = false;
  };

  _this.onRoll = function(roll) {
    if (roll) {
      _this.content.style.display = "none";
    }
    else {
      _this.content.style.display = "";
    }
  };

  _this.onDown = function() {
    _this.box.style.filter = "alpha(opacity=50)";
    _this.box.style.MozOpacity = "0.5";
    _this.box.style.KhtmlOpacity = "0.5";
    _this.box.style.opacity = "0.5";

    if (_this.box.style.opacity != "0.5") {
      return;
    }
    var style = hsGetComputedStyle(_this.content);
    _this.content.style.width = (
        _this.content.offsetWidth
        - hsParseInt(style.borderLeftWidth)
        - hsParseInt(style.borderRightWidth)
      ) + "px";
    _this.content.style.height = (
        _this.content.offsetHeight
        - hsParseInt(style.borderTopWidth)
        - hsParseInt(style.borderBottomWidth)
      ) + "px";

    _this.content.className = "hsFloatWindowContentBoxDis";
    _this.innerContent.style.display = "none";
    _this.innerWidth = _this.innerContent.style.width;
    _this.innerHeight = _this.innerContent.style.height;
  };

  _this.onUp = function() {
    _this.box.style.filter = "";
    _this.box.style.MozOpacity = "";
    _this.box.style.KhtmlOpacity = "";
    _this.box.style.opacity = "";

    var timeout = function(){
      if (_this.box.style.opacity != "") {
        return;
      }
      _this.content.style.width = "";
      _this.content.style.height = "";
      if (_this.width) {
        _this.content.style.width = _this.width + "px";
      }
      if (_this.height) {
        _this.content.style.width = _this.height + "px";
      }
    };
    setTimeout(timeout, 500);

    _this.content.className = "hsFloatWindowContentBox";
    _this.innerContent.style.display = "";
    _this.innerContent.style.width = _this.innerWidth;
    _this.innerContent.style.height = _this.innerHeight;
  };

  _this.onChange = function() {
    if (!_this.innerContent.src) {
      return;
    }

    // For IE
    if (_this.innerContent.readyState != null && _this.innerContent.readyState != "complete") {
      // IE 6 Bug
      if (HsBI.name == "MSIE" && HsBI.version < 7 && _this.scroll == "normal") {
        _this.innerContent.height = "";
      }
      return;
    }

    window.status = "";

    try {
      // Inner Window
      var iw = document.getElementById(_this.innerId);
      if (iw.contentWindow) {
        _this.innerWindow = iw.contentWindow; // In Firefox
      }
      else {
        _this.innerWindow = iw.window; // In IE
      }
      delete iw;

      // Init Window
      _this.innerWindow.HsFW = _this;
      if (_this.openerWindow) {
        _this.innerWindow.HsOW = _this.openerWindow;
      }
      else {
        _this.innerWindow.HsOW = self.HsPW;
      }
    }
    catch (ex) {
      hsError(self.floatWindowNoInnerWindowErr, "FloatWindow", ex.message);
      _this.close();
      return;
    }

    // Set Title
    if (_this.innerWindow.document.title) {
      _this.setTitle(_this.innerWindow.document.title);
    }

    _this.visible(true);
    _this.Cover.hide();

    // Set Focus
    if (_this.innerWindow.HsFE) {
      _this.innerWindow.HsFE.focus();
    }

    if (_this.innerWindow.HsFF){
      _this.innerWindow.HsFF();
    }

    if (_this.scroll == "normal") {
      _this.onResize(true);
      if(!_this.resizeHandle) {
        _this.resizeHandle = setInterval(_this.onResize, 500);
      }
    }
    else if (_this.scroll == "auto"
    && HsBI.name == "MSIE"
    && HsBI.version < 7.0) { // For IE 6
      _this.innerWindow.document.body.style.overflow = "hidden";
      if (_this.width < _this.innerWindow.document.body.offsetWidth) {
        _this.innerWindow.document.body.style.overflowX = "auto";
      }
      if (_this.height < _this.innerWindow.document.body.offsetHeight) {
        _this.innerWindow.document.body.style.overflowY = "auto";
      }
    }

    if (_this.forceLoad) {
      _this.forceLoad = false;
      _parent.center();
    }

    _this.onLoad();
  };

  _this.onResize = function(computeWidth) {
    try {
      if (_this.innerWindow.document
       && _this.resizeWidth == _this.innerWindow.document.body.offsetWidth
       && _this.resizeHeight == _this.innerWindow.document.body.offsetHeight) {
        return;
      }
    }
    catch (ex) {
      return;
    }

    if (_this.width == 0 && computeWidth) {
      // 检查目标页是否定义了宽度
      // 针对IE无法正确计算body.offsetWidth的BUG
      var w = 0;
      if (_this.innerWindow.document.body.width) {
        w = parseInt(_this.innerWindow.document.body.width);
      }
      else if (_this.innerWindow.document.body.style.width) {
        w = parseInt(_this.innerWindow.document.body.style.width);
      }
      else if (_this.innerWindow.hsMinWidth) {
        w = _this.innerWindow.hsMinWidth;
      }

      if (w) {
        _parent.pw = w + _this.left + _this.right;
        _this.box.style.width = _parent.pw + "px";
        _this.innerContent.style.width = w + "px";
      }
      else {
        _this.innerContent.style.width = _this.innerWindow.document.body.offsetWidth + "px";
        _parent.pw = _this.box.offsetWidth;
      }
    }

    if (_this.height == 0) {
      _this.innerContent.style.height = _this.innerWindow.document.body.offsetHeight + "px";
      _parent.ph = _this.box.offsetHeight;
    }

    _this.resizeWidth = _this.innerWindow.document.body.offsetWidth;
    _this.resizeHeight = _this.innerWindow.document.body.offsetHeight;
  };

  _this.onResize2 = function(computeWidth) {
    if (_this.resizeWidth == _this.innerContent.offsetWidth
     && _this.resizeHeight == _this.innerContent.offsetHeight) {
      return;
    }

    if (_this.width == 0 && computeWidth) {
      if (self.HsBI.name == "MSIE") {
        // 针对IE无法准确计算offsetWidth的BUG
        var w = _this.innerContent.offsetWidth;
        _parent.pw = w + _this.left + _this.right;
        _this.box.style.width = _parent.pw + "px";
        //_this.innerContent.style.width = w + "px";
      }
      else {
        //_this.innerContent.style.width = _this.innerContent.offsetWidth + "px";
        _parent.pw = _this.box.offsetWidth;
      }
    }

    if (_this.height == 0) {
      //_this.innerContent.style.height = _this.innerContent.offsetHeight + "px";
      _parent.ph = _this.box.offsetHeight;
    }

    _this.resizeWidth = _this.innerContent.offsetWidth;
    _this.resizeHeight = _this.innerContent.offsetHeight;
  };

  _this.onOpen = function() {};
  _this.onLoad = function() {};
  _this.onClose = function() {};

  _this.init();
}

/**
 * 浮动窗简化版
 *
 * 使用方法同"浮动窗构造器"
 *
 * @author HuangHong
 */
function HsFloatWindowSimpler (width, height, scroll, noCover, noScroll) {
  var tpl = {
    template : '<div class="hsFloatWindowSimpleBox" id="hsFloatWindowContentBox%ID%"></div>'
  };

  this.newMethod = HsFloatWindowCreator;
  this.newMethod(width, height, scroll, true, true, noCover, noScroll, tpl);
}

/** Javascript补充 **/

/**
 * 补充 String.prototype.trim 方法
 *
 * @author HuangHong
 */
if (! String.prototype.trim)
String.prototype.trim = function() {
  return this.replace(/(^\s*)|(\s*$)/g, "");
};

/**
 * 补充 String.prototype.getBytes 方法
 *
 * @author HuangHong
 */
if (! String.prototype.getBytes)
String.prototype.getBytes = function() {
  var cArr = this.match(/[^\x00-\xff]/ig);
  return this.length + (cArr == null ? 0 : cArr.length);
};

/**
 * 补充 document.getElementsByClassName 方法
 *
 * @author HuangHong
 */
if (! document.getElementsByClassName)
document.getElementsByClassName = function(className) {
  className = " " + className + " ";
  var classElements = [];
  var elements = this.getElementsByTagName("*");
  for (var i = 0; i < elements.length; i ++) {
    var classNames = " " + elements[i].className + " ";
    if (classNames.indexOf(className) !== -1) {
      classElements.push(elements[i]);
    }
  }
  return classElements;
};

/** 初始化 **/

void function() {
  // 浏览器信息(Browser Info)
  self.HsBI = hsGetBrowserInfo();
  if (self.HsBI == null) {
    self.HsBI = {
      "name"    : "Unsupported",
      "version" : 0
    };
  }

  // 父级窗口(Parent Window)和顶级窗口(Top Window)
  var w = self;
  while (w.parent != w.self && w.parent.hsError != undefined) {
    w = w.parent;
    if (!self.HsPW) {
      self.HsPW = w;
    }
  }
  if (!self.HsPW) {
    self.HsPW = w;
  }
  self.HsTW = w;
  delete w;
}();
